package com.cloudptt.api.product.operator;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.cloudptt.api.comm.CauseCont;
import com.cloudptt.api.models.lbs.ReportData;
import com.cloudptt.api.product.func.SipOperator;
import com.cloudptt.api.product.log.Log;
import com.mcptt.config.body.info.mcptt.McpttInfoBody_Location;
import com.mcptt.db.loader.msg.MapPointListLoader;
import com.mcptt.db.loader.msg.MapPointListLoaderCb;
import com.mcptt.http.operator.OkHttpUtils;

import android.content.Context;
import android.os.RemoteException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class LBSOperator extends SipOperator implements Callback{


	private static final String THIS_FILE = "LBSOperator";
	 
	public LBSOperator(Context ctx) {
		super(ctx);
	}
	
	
	public int sendSysMsg(String msgStr)  throws RemoteException
	{
		Log.d(THIS_FILE, "sendSysMsg msgStr = " + msgStr);
		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return result;
		}
		service.sendSystemMessage(msgStr);
		return CauseCont.OperateCheck_Suc;
	}
	
	
	
//	public int requestUserLocation(String mcpttId)
//	{
//		Log.d(THIS_FILE, "requestUserLocation mcpttId = " + mcpttId);
//		int result = checkFirst();
//		if(CauseCont.OperateCheck_Suc != result)
//		{
//			return result;
//		}
//		
//		McpttInfoBody_Location infoBody = new McpttInfoBody_Location(mcpttId);
//		String infoStr = infoBody.toString();
//		LocationInfoBody_Request locationInfoBody = new LocationInfoBody_Request(mcpttId);
//		String locationInfoStr = locationInfoBody.toString();
//		
//		try {
//			return service.sendLocationMessage(false,infoStr,locationInfoStr);
//		} catch (RemoteException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//			return CauseCont.OperateErr_Exception;
//		}
//	}
	
//	public int requestUserSerialLocation(String mcpttId,int timeInterval,int distanceInterval)
//	{
//		Log.d(THIS_FILE, "requestUserLocation mcpttId = " + mcpttId);
//		int result = checkFirst();
//		if(CauseCont.OperateCheck_Suc != result)
//		{
//			return result;
//		}
//		
//		McpttInfoBody_Location infoBody = new McpttInfoBody_Location(mcpttId);
//		String infoStr = infoBody.toString();
//		LocationInfoBody_Configuration locationInfoBody = new LocationInfoBody_Configuration(mcpttId,timeInterval,distanceInterval);
//		String locationInfoStr = locationInfoBody.toString();
//		
//		try {
//			return service.sendLocationMessage(false,infoStr,locationInfoStr);
//		} catch (RemoteException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//			return CauseCont.OperateErr_Exception;
//		}
//	}
	
	public int reportLocation(String dataStr)
	{
//		Log.d(THIS_FILE, "reportLocation data = " + data );
		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return result;
		}
		if(dataStr == null)
		{
			return CauseCont.OperateErr_DataNull;
		}
		
		try {

			result = service.sendLocationMessage(dataStr);
//			Log.d(THIS_FILE, "reportLocation result = " + result);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			Log.d(THIS_FILE, "reportLocation OperateErr_Exception");
			return CauseCont.OperateErr_Exception;
		}
		return result;
	}
	
	@Override
	public void onFailure(Call arg0, IOException e) {
		// TODO Auto-generated method stub
		Log.debug(getClass(), "onFailure e = " + e);
		if(e != null)
		{
			e.printStackTrace();
		}
	}

	@Override
	public void onResponse(Call arg0, Response response) throws IOException {
		// TODO Auto-generated method stub
		Log.debug(getClass(), "onResponse response = " + response);
		if(response == null)
		{
			return;
		}

		
	}
	
	public MapPointListLoader geMapPointListLoaderCb(Context ctx, MapPointListLoaderCb callback)
	{
		return null;//new MapPointListLoader(ctx, callback);
	}
}
